package priv.abadstring.study.haoke.dubbo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;
import priv.abadstring.study.haoke.dubbo.entity.Ad;
import priv.abadstring.study.haoke.dubbo.service.AdService;
import priv.abadstring.study.haoke.dubbo.service.BaseServiceImpl;
import priv.abadstring.study.haoke.dubbo.dto.PageInfo;

/**
 * AdServiceImpl
 *
 * @author aBadString
 * @date 2021-06-18 18:49:33
 */
@Service
public class AdServiceImpl extends BaseServiceImpl<Ad> implements AdService {
    @Override
    public PageInfo<Ad> queryAdList(Ad ad, Integer page, Integer pageSize) {
        QueryWrapper<Ad> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("updated");
        wrapper.eq("type", ad.getType());
        IPage<Ad> pageList = super.queryPageList(wrapper, page, pageSize);
        return new PageInfo<>(
                (int) pageList.getTotal(),
                (int) pageList.getCurrent(),
                (int) pageList.getSize(),
                pageList.getRecords()
        );
    }
}
